/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package DAO;

import DTO.NhatKyHeThong_DTO;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

/**
 *
 * @author Phung
 */
public class NhatKyHeThong_DAO {
    
    public static ArrayList<NhatKyHeThong_DTO> GetALL()
    {
        ArrayList<NhatKyHeThong_DTO> ds = new ArrayList<>();
        try {
            String sql = "Select * from NhatKyHeThong" ;
            MySQLDataHelper_DAO.open();
            ResultSet rs =  MySQLDataHelper_DAO.executeQuery(sql);
            while (rs.next()) {
                NhatKyHeThong_DTO NhatKy = new NhatKyHeThong_DTO();
                NhatKy.setID(rs.getInt("ID"));
                NhatKy.setTenTK(rs.getString("TenTK"));
                NhatKy.setTenMay(rs.getString("TenMay"));
                NhatKy.setThoiGian(rs.getDate("ThoiGian"));
                NhatKy.setThaoTac(rs.getString("ThaoTac"));
                NhatKy.setGhiChu(rs.getString("GhiChu"));
                ds.add(NhatKy);
            }
            MySQLDataHelper_DAO.close();
       }catch (SQLException ex) {
            System.out.println(ex);
        }
        return ds;
    }
    
    public static boolean Insert(NhatKyHeThong_DTO NhatKy)
    {
        boolean flag = false;
        try {
            java.text.SimpleDateFormat fmt = new java.text.SimpleDateFormat("yyyy-MM-dd");
            String ThoiGian = fmt.format(NhatKy.getThoiGian());
            String sql = "Insert NhatKyHeThong(TenTK, TenMay, ThoiGian, ThaoTac, GhiChu) Values('"+NhatKy.getTenTK()+"','"+NhatKy.getTenMay()+"','"+ ThoiGian +"','"+NhatKy.getThaoTac()+"','"+NhatKy.getGhiChu()+"')";
            MySQLDataHelper_DAO.open();
            int kq = MySQLDataHelper_DAO.executeUpdate(sql);
            if(kq == 1)
                flag =true;
            MySQLDataHelper_DAO.close();
        }catch (Exception ex) {
            System.out.println(ex);
        }
        return flag;
    } 
}
